package com.cdtu.outtake.controller;

import com.cdtu.outtake.common.Result;
import com.cdtu.outtake.dto.CommentDto;
import com.cdtu.outtake.controller.vo.CommentVO;
import com.cdtu.outtake.service.ICommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : shl
 * @Date 2024/4/16 13:31
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/comment")
public class CommentController {

    private final ICommentService commentService;

    @PostMapping
    public Result<Object> addComment(@RequestBody CommentVO comment) {
        commentService.createComment(comment);
        return Result.ok();
    }

    //TODO 获取自己的评论
    @GetMapping
    public Result<List<CommentDto>> getMyComments() {
        return Result.ok(commentService.getMyComments());
    }

    //TODO 获取商铺的评论
    @GetMapping("/{id}")
    public Result<Object> getShopComments(@PathVariable("id") Long id) {
        return Result.ok(commentService.getShopComments(id));
    }

    @DeleteMapping("/{id}")
    public Result<Object> deleteComment(@PathVariable("id") Long id) {
        commentService.deleteById(id);
        return Result.ok();
    }
}
